package com.fly.service;

import com.fly.domain.Menu;
import com.fly.domain.Role;
import com.fly.domain.User;
import com.fly.mapper.DepartmentMapper;
import com.fly.mapper.MenuMapper;
import com.fly.repository.MenuRepository;
import com.fly.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;


/**
 * @author Fly
 * @Description
 * @Date Created in 14:21 2018/1/24
 * @Modified by
 */
@Service
public class MenuService extends CurdService<MenuRepository, Menu> {

    @Autowired
    private MenuMapper menuMapper;

    /**
     * 获取当前用户的授权菜单
     * @return
     */
    public List<Menu> getCurrentMenus(){
        User user = UserUtils.getCurrentUser();
        if(user.isAdmin()){
            return getTreeData(Long.valueOf(-1));
        }else {
            return menuMapper.getMenusByUserId(user.getId());
        }
    }

    /**
     * 根据角色ID查询菜单
     * @param roleId
     * @return
     */
    public List<Long> getMenusByRoleId(Long roleId){
        return menuMapper.getMenuIdsByRoleId(roleId);
    }
    /**
     * 获取树
     * @param parentId
     * @return
     */
    public List<Menu> getTreeData(Long parentId) {
        return menuMapper.getMenusByParentId(parentId);
    }

}
